package com.xdf.ecommerce.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * @author chanchaw
 * @create 2025-10-27 19:13
 */
public enum GoodsStatus {
    OFFLINE(0,"offline","下线"),
    ONLINE(1,"online","上线"),
    STOCK_OUT(2,"stockOut","缺货"),
    ;
    private int id;
    private String sid;
    private String remark;
    public int getId() {return id;}
    public String getSid() {return sid;}
    public String getRemark() {return remark;}

    GoodsStatus(int id,String sid, String remark) {
        this.id = id;
        this.sid = sid;
        this.remark = remark;
    }

    // 根据索引返回枚举值
    public static GoodsStatus of(int id){
        return ofid(id);
    }
    public static GoodsStatus ofid(int id){
        for(GoodsStatus item:GoodsStatus.values()){
            if(item.getId() == id) return item;
        }
        return null;
    }

    public static GoodsStatus ofsid(String sid){
        for(GoodsStatus item:GoodsStatus.values()){
            if(item.getSid().equals(sid)) return item;
        }
        return null;
    }
}
